package com.br.gvttv.util;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

import com.br.negocio.entidades.PacoteEnum;

public class SharedPreferencesUtils {

	public static final String CONFIG_PACOTES_CANAL = "configPacotesCanal";

	public static final void iniciarConfiguracaoPacoteCanal(Context context) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				CONFIG_PACOTES_CANAL, Context.MODE_PRIVATE);

		if (sharedPreferences.getAll().isEmpty()) {
			Editor edit = sharedPreferences.edit();

			for (PacoteEnum pacoteEnum : PacoteEnum.values()) {
				edit.putBoolean(pacoteEnum.toString(), pacoteEnum.isAtivo());
			}

			edit.commit();
		}
	}

	public static boolean getConfiguracaoPacoteCanal(Context context,
			PacoteEnum pacoteEnum) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				CONFIG_PACOTES_CANAL, Context.MODE_PRIVATE);
		return (Boolean) sharedPreferences.getAll().get(pacoteEnum.toString());
	}

	public static List<PacoteEnum> getConfiguracaoPacoteCanalAtivos(
			Context context) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				CONFIG_PACOTES_CANAL, Context.MODE_PRIVATE);
		List<PacoteEnum> pacoteEnum = new ArrayList<PacoteEnum>();

		for (String key : sharedPreferences.getAll().keySet()) {
			if ((Boolean) sharedPreferences.getAll().get(key)) {
				pacoteEnum.add(PacoteEnum.valueOf(key));
			}
		}

		return pacoteEnum;
	}

	public static void setConfiguracaoPacoteCanal(Context context,
			PacoteEnum pacoteEnum, boolean ativo) {
		Editor edit = context.getSharedPreferences(CONFIG_PACOTES_CANAL,
				Context.MODE_PRIVATE).edit();
		edit.putBoolean(pacoteEnum.toString(), ativo);
		edit.commit();
	}
}
